package com.wjc.myktapplication.data

import android.app.Application
import com.wjc.myktapplication.BuildConfig
import com.wjc.network.INetworkRequiredInfo
import com.wjc.network.RetrofitFactory
import io.reactivex.rxjava3.core.SingleObserver

/**
 * ClassName: com.wjc.myktapplication.manager
 * Description:
 * JcChen on 2021.04.16.18:03
 */
object NetworkManager {
    private const val DEBUG_URL = "https://www.wanandroid.com"
    private const val PRODUCT_URL = "https://www.wanandroid.com"
    fun init(application: Application, devEnv: Int) {
        RetrofitFactory.init(object : INetworkRequiredInfo {
            override fun fetchApplicationContext(): Application {
                return application
            }

            override fun fetchBaseUrl() =
                if (devEnv == BuildConfig.DEL_EVN) DEBUG_URL else PRODUCT_URL
        })

    }

    fun fetchApiService() = RetrofitFactory.getService(NetworkApi::class.java)

    fun <T> applySchedulers(observer: SingleObserver<T>) = RetrofitFactory.applySchedulers(observer)

}